package com.hiwhitley.leetcode.easy;

/**
 * Created by hiwhitley on 17-1-16.
 */
public class LongestCommonPrefix_14 {
    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0)
            return "";
        int len = strs.length;
        int minLen = Integer.MIN_VALUE;
        String s = "";
        for (int i = 0; i < len; i++) {
            if (minLen < strs[i].length()) {
                s = strs[i];
                minLen = s.length();
            }
        }

        for (int i = 0; i < len; i++) {
            while (strs[i].indexOf(s) != 0) {
                s = s.substring(0, s.length() - 1);
            }
        }
        return s;
    }
}
